/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package counter.stosc.com;

import java.io.*;


/**
 *
 * @author Stosc
 */
public final class Counter {

    private int id;
    private String counterName;
    private int scheduleCount;
    private int completeConut;
    private double completePercentum;
    private long jobDate;

    public Counter(){
    }

    public Counter(String counterName, int scheduleCount){
        this.id = 0;
        this.counterName = counterName;
        this.scheduleCount = scheduleCount;
        this.completeConut = 0;
        this.completePercentum = 0;
        this.jobDate = System.currentTimeMillis();
    }
    /**
     * 序列化对象
     */
    public void serialize(DataOutputStream dos) throws IOException{
        dos.writeInt(id);
        dos.writeUTF(counterName);
        dos.writeInt(scheduleCount);
        dos.writeInt(completeConut);
        dos.writeDouble(completePercentum);
        dos.writeLong(System. currentTimeMillis());
        dos.flush();
    }

    /**
     * 反序列化对象
     */
    public static Counter deserialize(DataInputStream dis) throws IOException{
        Counter counter = new Counter();
        counter.setId(dis.readInt());
        counter.setCounterName(dis.readUTF());
        counter.setScheduleCount(dis.readInt());
        counter.setCompleteConut(dis.readInt());
        counter.setCompletePercentum(dis.readDouble());
        counter.setJobDate(dis.readLong());
        return counter;
    }

    public int compareTo(Counter counter){
        int i = (int) (this.jobDate - counter.jobDate);
        return i;
    }

    public int hashCode() {
        int hash = 5;
        hash = 67 * hash + this.id;
        return hash;
    }

    public boolean equals(Object obj){
        if(this == obj){
            return true;
        }
        if(obj instanceof Counter){
            return ((Counter)obj).id == this.id;
        }
        return false;
    }
    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the counterName
     */
    public String getCounterName() {
        return counterName;
    }

    /**
     * @param counterName the counterName to set
     */
    public void setCounterName(String counterName) {
        this.counterName = counterName;
    }

    /**
     * @return the scheduleCount
     */
    public int getScheduleCount() {
        return scheduleCount;
    }

    /**
     * @param scheduleCount the scheduleCount to set
     */
    public void setScheduleCount(int scheduleCount) {
        this.scheduleCount = scheduleCount;
    }

    /**
     * @return the completeConut
     */
    public int getCompleteConut() {
        return completeConut;
    }

    /**
     * @param completeConut the completeConut to set
     */
    public void setCompleteConut(int completeConut) {
        this.completeConut = completeConut;
    }

    /**
     * @return the completePercentum
     */
    public double getCompletePercentum() {
        return completePercentum;
    }

    /**
     * @param completePercentum the completePercentum to set
     */
    public void setCompletePercentum(double completePercentum) {
        this.completePercentum = completePercentum;
    }

    /**
     * @return the jobDate
     */
    public long getJobDate() {
        return jobDate;
    }

    /**
     * @param jobDate the jobDate to set
     */
    public void setJobDate(long jobDate) {
        this.jobDate = jobDate;
    }



}
